function checkPassword(form)
  {
    var pass1 = document.getElementById('password').value;
    var pass2 = document.getElementById('confirmpassword').value;
    var inputtext = document.getElementById('confirmpassword');
    var message = document.getElementById('confirmMessage');
    var goodColor = "#66cc66";
    var badColor = "#ff6666";
    if(pass1 != "" && pass1 == pass2) {
      if(pass1.length < 6) {
        inputtext.style.backgroundColor = badColor;
        message.style.color = badColor;
        message.innerHTML = "Error: Password must contain at least six characters!";
        pass1.focus();
        return false;
      }
    
    if(pass1.length > 15) {
        inputtext.style.backgroundColor = badColor;
        message.style.color = badColor;
        message.innerHTML = "Error: Password must contain at most fifteen characters!";
        pass1.focus();
        return false;
      }
    
      re = /[0-9]/;
      if(!re.test(pass1)) {
        inputtext.style.backgroundColor = badColor;
        message.style.color = badColor;
        message.innerHTML = "Error: Password must contain at least one number (0-9)!";
        pass1.focus();
        return false;
      }
      re = /[a-z]/;
      if(!re.test(pass1)) {
        inputtext.style.backgroundColor = badColor;
        message.style.color = badColor;
        message.innerHTML = "Error: Password must contain at least one lowercase letter (a-z)!";
        pass1.focus();
        return false;
      }
      re = /[A-Z]/;
      if(!re.test(pass1)) {
        inputtext.style.backgroundColor = badColor;
        message.style.color = badColor;
        message.innerHTML = "Error: Password must contain at least one uppercase letter (A-Z)!";
        pass1.focus();
        return false;
      }
    } else {
        inputtext.style.backgroundColor = badColor;
        message.style.color = badColor;
        message.innerHTML = "Passwords Do Not Match!";
      pass1.focus();
      return false;
    }
    inputtext.style.backgroundColor = goodColor;
    message.style.color = goodColor;
    message.innerHTML = "Passwords Match!";
    return true;
  }

  function checkForm(form)
  {
    if (!checkNif(form.nif.value)){
        form.nif.focus();
        return false;
    }
    if (!checkPassword(form.nif.value)){
        form.nif.focus();
        return false;
    }
    return true;
  }

function checkNif(field)
{
  var value=String(field);
  numbers=value.substring(0,2)+value.substring(3,6)+value.substring(7,10);
  letter = value[11];
  value=numbers+letter;
  exp_reg = /^[0-9]{8}[a-zA-Z]{1}$/;
  if ( exp_reg.test(value) == false )
    {
    alert("The NIF you provided: "+value+" is not valid");
    return false;
    }
  else
    {
    letter2 = checkLetter(numbers);
    if (letter != letter2){
      alert("The letter of the NIF you provided: "+value+" is not valid");
      return false;
    }
    else{
      return true;
    }
  }
  return true;
}
function checkLetter(nif)
{
  str="TRWAGMYFPDXBNJZSQVHLCKET";
  position = parseInt(nif) % 23;
  l = str.substring(position,position+1);
  return l;
}

function checkEmail(email){

  var res = str.split(" ");

}